// Game Reservation System for KING神电竞
class ReservationSystem {
    constructor() {
        this.bookings = JSON.parse(localStorage.getItem('bookings')) || [];
        this.prices = JSON.parse(localStorage.getItem('prices')) || {
            rank: 50,
            teach: 80,
            team: 60,
            tactics: 100
        };
        this.activities = JSON.parse(localStorage.getItem('activities')) || [];
        this.settings = JSON.parse(localStorage.getItem('settings')) || {
            description: 'KING神电竞是专业的永劫无间陪玩团队，拥有50+专业陪玩，1000+满意客户，99%好评率。我们提供段位陪练、技术教学、组队开黑、战术指导等全方位服务。',
            contact: '微信：wq10880 | QQ：2424135780 | 电话：18922402676'
        };
        this.adminLoggedIn = false;
        
        this.init();
    }

    init() {
        this.setupEventListeners();
        this.updatePricesDisplay();
        this.loadSettings();
    }

    setupEventListeners() {
        // Customer reservation form
        const reservationForm = document.getElementById('reservationForm');
        if (reservationForm) {
            reservationForm.addEventListener('submit', (e) => this.handleReservation(e));
        }

        // Admin login - 修复事件绑定
        const adminLoginForm = document.getElementById('adminLoginForm');
        if (adminLoginForm) {
            adminLoginForm.addEventListener('submit', (e) => {
                e.preventDefault();
                this.handleAdminLogin(e);
            });
        }

        // Admin login button
        const adminLoginBtn = document.querySelector('.admin-btn');
        if (adminLoginBtn) {
            adminLoginBtn.addEventListener('click', (e) => {
                e.preventDefault();
                this.openAdminModal();
            });
        }

        // Navigation
        const navLinks = document.querySelectorAll('.nav-link');
        navLinks.forEach(link => {
            link.addEventListener('click', (e) => {
                if (!link.classList.contains('admin-btn')) {
                    e.preventDefault();
                    const target = link.getAttribute('href').substring(1);
                    this.scrollToSection(target);
                }
            });
        });

        // 确保DOM加载完成后再绑定事件
        if (document.readyState === 'loading') {
            document.addEventListener('DOMContentLoaded', () => {
                this.bindAdminEvents();
            });
        } else {
            this.bindAdminEvents();
        }
    }

    bindAdminEvents() {
        // 重新绑定管理员登录表单事件
        const adminLoginForm = document.getElementById('adminLoginForm');
        if (adminLoginForm) {
            adminLoginForm.addEventListener('submit', (e) => {
                e.preventDefault();
                this.handleAdminLogin(e);
            });
        }
    }

    handleReservation(e) {
        e.preventDefault();
        
        const formData = new FormData(e.target);
        const booking = {
            id: Date.now().toString(),
            gameName: document.getElementById('gameName').value,
            serviceType: document.getElementById('serviceType').value,
            bookingTime: document.getElementById('bookingTime').value,
            contact: document.getElementById('contact').value,
            requirements: document.getElementById('requirements').value,
            status: 'pending',
            createdAt: new Date().toISOString(),
            price: this.calculatePrice(document.getElementById('serviceType').value)
        };

        this.bookings.push(booking);
        this.saveBookings();
        
        alert('预约成功！我们会尽快联系您确认预约信息。');
        e.target.reset();
        
        // Update admin dashboard if logged in
        if (this.adminLoggedIn) {
            this.displayBookings();
        }
    }

    calculatePrice(serviceType) {
        let basePrice = this.prices[serviceType] || 50;
        
        // Apply active discount
        const activeActivity = this.activities.find(a => a.active);
        if (activeActivity) {
            basePrice = basePrice * (activeActivity.discount / 100);
        }
        
        return Math.round(basePrice);
    }

    handleAdminLogin(e) {
        e.preventDefault();
        
        const username = document.getElementById('adminUser').value.trim();
        const password = document.getElementById('adminPass').value.trim();
        
        console.log('登录验证:', {
            username: username,
            password: password,
            usernameLength: username.length,
            passwordLength: password.length,
            usernameMatch: username === 'admin',
            passwordMatch: password === 'king888'
        });
        
        // 强制验证 - 添加trim和严格匹配检查
        if (username === 'admin' && password === 'king888') {
            this.adminLoggedIn = true;
            this.closeAdminModal();
            this.showAdminDashboard();
            alert('✅ 管理员登录成功！');
        } else {
            alert(`❌ 登录失败！\n\n用户名: "${username}" (${username.length}个字符)\n密码: "${password}" (${password.length}个字符)\n\n请确保输入完全匹配：\n用户名: admin\n密码: king888`);
        }
    }

    showAdminDashboard() {
        console.log('显示管理后台');
        const dashboard = document.getElementById('adminDashboard');
        if (dashboard) {
            dashboard.style.display = 'block';
            // 隐藏主页面内容
            document.body.style.overflow = 'hidden';
            
            // 隐藏header和footer
            const header = document.querySelector('.header');
            const footer = document.querySelector('.footer');
            const main = document.querySelector('main');
            
            if (header) header.style.display = 'none';
            if (footer) footer.style.display = 'none';
            if (main) main.style.display = 'none';
            
            this.displayBookings();
            this.loadAdminSettings();
            this.showTab('bookings'); // 默认显示预约管理
            
            // 更新导航显示
            this.updateNavForAdmin(true);
        } else {
            console.error('找不到管理后台元素');
        }
    }

    hideAdminDashboard() {
        const dashboard = document.getElementById('adminDashboard');
        if (dashboard) {
            dashboard.style.display = 'none';
            
            // 显示主页面内容
            document.body.style.overflow = 'auto';
            
            // 显示header和footer
            const header = document.querySelector('.header');
            const footer = document.querySelector('.footer');
            const main = document.querySelector('main');
            
            if (header) header.style.display = 'flex';
            if (footer) footer.style.display = 'block';
            if (main) main.style.display = 'block';
            
            // 更新导航显示
            this.updateNavForAdmin(false);
        }
    }

    logoutAdmin() {
        this.adminLoggedIn = false;
        this.hideAdminDashboard();
        alert('已退出管理员账户');
    }

    updateNavForAdmin(isAdmin) {
        const adminBtn = document.querySelector('.admin-btn');
        if (adminBtn) {
            if (isAdmin) {
                adminBtn.textContent = '管理后台';
                adminBtn.onclick = () => this.showAdminDashboard();
            } else {
                adminBtn.textContent = '管理员登录';
                adminBtn.onclick = () => this.openAdminModal();
            }
        }
    }

    displayBookings() {
        const bookingsList = document.getElementById('bookingsList');
        if (!bookingsList) return;

        if (this.bookings.length === 0) {
            bookingsList.innerHTML = '<p>暂无预约记录</p>';
            return;
        }

        const bookingsHTML = this.bookings.map(booking => `
            <div class="booking-item">
                <div class="booking-info">
                    <strong>预约编号:</strong> ${booking.id}<br>
                    <strong>游戏昵称:</strong> ${booking.gameName}<br>
                    <strong>服务类型:</strong> ${this.getServiceName(booking.serviceType)}<br>
                    <strong>预约时间:</strong> ${new Date(booking.bookingTime).toLocaleString('zh-CN')}<br>
                    <strong>联系方式:</strong> ${booking.contact}<br>
                    <strong>价格:</strong> ¥${booking.price}<br>
                    <strong>特殊要求:</strong> ${booking.requirements || '无'}<br>
                    <strong>创建时间:</strong> ${new Date(booking.createdAt).toLocaleString('zh-CN')}<br>
                    <strong>状态:</strong> <span class="booking-status status-${booking.status}">${this.getStatusName(booking.status)}</span>
                </div>
                <div class="booking-actions">
                    <button class="action-btn" onclick="reservationSystem.showBookingDetails('${booking.id}')" style="background: #17a2b8; color: white;">详情</button>
                    ${booking.status === 'pending' ? 
                        `<button class="action-btn confirm-btn" onclick="reservationSystem.updateBookingStatus('${booking.id}', 'confirmed')">确认</button>
                         <button class="action-btn cancel-btn" onclick="reservationSystem.updateBookingStatus('${booking.id}', 'cancelled')">取消</button>` : ''}
                    ${booking.status === 'confirmed' ? 
                        `<button class="action-btn confirm-btn" onclick="reservationSystem.updateBookingStatus('${booking.id}', 'completed')">完成</button>
                         <button class="action-btn" onclick="reservationSystem.sendReminder('${booking.id}')" style="background: #ffc107; color: black;">提醒</button>` : ''}
                    ${booking.status === 'completed' ? 
                        `<button class="action-btn" onclick="reservationSystem.markReviewed('${booking.id}')" style="background: #6f42c1; color: white;">已回访</button>` : ''}
                </div>
            </div>
        `).join('');

        bookingsList.innerHTML = bookingsHTML;
    }

    showBookingDetails(bookingId) {
        const booking = this.bookings.find(b => b.id === bookingId);
        if (booking) {
            const details = `
📋 预约详情
━━━━━━━━━━━━━━━━━━━━━
🔢 预约编号: ${booking.id}
👤 游戏昵称: ${booking.gameName}
🎮 服务类型: ${this.getServiceName(booking.serviceType)}
📅 预约时间: ${new Date(booking.bookingTime).toLocaleString('zh-CN')}
📱 联系方式: ${booking.contact}
💰 价格: ¥${booking.price}
📝 特殊要求: ${booking.requirements || '无'}
⏰ 创建时间: ${new Date(booking.createdAt).toLocaleString('zh-CN')}
📊 当前状态: ${this.getStatusName(booking.status)}
            `;
            alert(details);
        }
    }

    sendReminder(bookingId) {
        const booking = this.bookings.find(b => b.id === bookingId);
        if (booking) {
            alert(`已发送提醒给 ${booking.contact}，提醒内容：\n\n您的${this.getServiceName(booking.serviceType)}预约时间快到了，请准时参加！`);
        }
    }

    markReviewed(bookingId) {
        const booking = this.bookings.find(b => b.id === bookingId);
        if (booking) {
            booking.reviewed = true;
            this.saveBookings();
            this.displayBookings();
            alert('已标记为已回访！');
        }
    }

    getServiceName(serviceType) {
        const serviceNames = {
            rank: '段位陪练',
            teach: '技术教学',
            team: '组队开黑',
            tactics: '战术指导'
        };
        return serviceNames[serviceType] || serviceType;
    }

    getStatusName(status) {
        const statusNames = {
            pending: '待确认',
            confirmed: '已确认',
            completed: '已完成',
            cancelled: '已取消'
        };
        return statusNames[status] || status;
    }

    updateBookingStatus(bookingId, newStatus) {
        const bookingIndex = this.bookings.findIndex(b => b.id === bookingId);
        if (bookingIndex !== -1) {
            this.bookings[bookingIndex].status = newStatus;
            this.saveBookings();
            this.displayBookings();
        }
    }

    updatePrices() {
        this.prices.rank = parseInt(document.getElementById('priceRank').value) || 50;
        this.prices.teach = parseInt(document.getElementById('priceTeach').value) || 80;
        this.prices.team = parseInt(document.getElementById('priceTeam').value) || 60;
        this.prices.tactics = parseInt(document.getElementById('priceTactics').value) || 100;
        
        this.savePrices();
        this.updatePricesDisplay();
        alert('价格已更新！');
    }

    updatePricesDisplay() {
        const priceElements = document.querySelectorAll('[data-price]');
        priceElements.forEach(element => {
            const serviceType = element.getAttribute('data-price');
            const price = this.calculatePrice(serviceType);
            element.textContent = `¥${price}/小时起`;
        });
    }

    addActivity() {
        const title = document.getElementById('activityTitle').value;
        const content = document.getElementById('activityContent').value;
        const discount = parseInt(document.getElementById('activityDiscount').value) || 100;

        if (!title || !content) {
            alert('请填写活动标题和内容！');
            return;
        }

        // Deactivate other activities
        this.activities.forEach(a => a.active = false);

        const activity = {
            id: Date.now().toString(),
            title,
            content,
            discount,
            active: true,
            createdAt: new Date().toISOString()
        };

        this.activities.push(activity);
        this.saveActivities();
        this.displayActivities();
        this.updatePricesDisplay();
        
        // Clear form
        document.getElementById('activityTitle').value = '';
        document.getElementById('activityContent').value = '';
        document.getElementById('activityDiscount').value = '100';
        
        alert('活动已添加！');
    }

    displayActivities() {
        const activitiesList = document.getElementById('activitiesList');
        if (!activitiesList) return;

        if (this.activities.length === 0) {
            activitiesList.innerHTML = '<p>暂无活动</p>';
            return;
        }

        const activitiesHTML = this.activities.map(activity => `
            <div class="booking-item">
                <div class="booking-info">
                    <strong>${activity.title}</strong><br>
                    <small>${activity.content}</small><br>
                    <strong>折扣: ${activity.discount}%</strong><br>
                    <strong>状态: ${activity.active ? '激活' : '未激活'}</strong>
                </div>
                <div class="booking-actions">
                    <button class="action-btn ${activity.active ? 'cancel-btn' : 'confirm-btn'}" 
                            onclick="reservationSystem.toggleActivity('${activity.id}')">
                        ${activity.active ? '停用' : '激活'}
                    </button>
                    <button class="action-btn cancel-btn" 
                            onclick="reservationSystem.deleteActivity('${activity.id}')">
                        删除
                    </button>
                </div>
            </div>
        `).join('');

        activitiesList.innerHTML = activitiesHTML;
    }

    toggleActivity(activityId) {
        const activityIndex = this.activities.findIndex(a => a.id === activityId);
        if (activityIndex !== -1) {
            // If activating this activity, deactivate others
            if (!this.activities[activityIndex].active) {
                this.activities.forEach(a => a.active = false);
            }
            this.activities[activityIndex].active = !this.activities[activityIndex].active;
            this.saveActivities();
            this.displayActivities();
            this.updatePricesDisplay();
        }
    }

    deleteActivity(activityId) {
        if (confirm('确定要删除这个活动吗？')) {
            this.activities = this.activities.filter(a => a.id !== activityId);
            this.saveActivities();
            this.displayActivities();
            this.updatePricesDisplay();
        }
    }

    updateSettings() {
        this.settings.description = document.getElementById('storeDescription').value;
        this.settings.contact = document.getElementById('storeContact').value;
        
        this.saveSettings();
        this.loadSettings();
        this.updateContactDisplay(); // 同步更新首页显示
        alert('店铺设置已更新！');
    }

    updateContactDisplay() {
        // 更新首页联系信息显示
        const contactItems = document.querySelectorAll('.contact-item span');
        if (contactItems.length >= 3) {
            // 解析联系信息并更新显示
            const contactInfo = this.settings.contact;
            
            // 使用正则表达式提取微信、QQ、电话
            const weixinMatch = contactInfo.match(/微信：([^|]+)/);
            const qqMatch = contactInfo.match(/QQ：([^|]+)/);
            const phoneMatch = contactInfo.match(/电话：([^|]+)/);
            
            if (weixinMatch) {
                contactItems[0].textContent = '微信：' + weixinMatch[1].trim();
            }
            if (qqMatch) {
                contactItems[1].textContent = 'QQ：' + qqMatch[1].trim();
            }
            if (phoneMatch) {
                contactItems[2].textContent = '电话：' + phoneMatch[1].trim();
            }
        }
    }

    loadSettings() {
        document.getElementById('storeDescription').value = this.settings.description || '';
        document.getElementById('storeContact').value = this.settings.contact || '';
        this.updateContactDisplay(); // 加载时更新联系信息显示
    }

    loadAdminSettings() {
        document.getElementById('priceRank').value = this.prices.rank;
        document.getElementById('priceTeach').value = this.prices.teach;
        document.getElementById('priceTeam').value = this.prices.team;
        document.getElementById('priceTactics').value = this.prices.tactics;
        this.loadSettings();
        this.displayActivities();
        this.loadHomepageSettings();
    }

    loadHomepageSettings() {
        // 加载首页设置
        const homepageSettings = JSON.parse(localStorage.getItem('homepageSettings')) || {
            heroTitle: '永劫无间专业陪玩服务',
            heroSubtitle: '顶级技术大神带你飞，专业团队，安全可靠',
            heroBgImage: '',
            stat1Text: '1000+满意客户',
            stat2Text: '50+专业陪玩',
            stat3Text: '99%好评率',
            serviceDescriptions: {
                rank: '专业大神带你上分，快速提升段位',
                teach: '一对一指导，掌握核心技巧',
                team: '与大神组队，体验高端局',
                tactics: '战术分析，制定专属策略'
            }
        };

        document.getElementById('heroTitle').value = homepageSettings.heroTitle;
        document.getElementById('heroSubtitle').value = homepageSettings.heroSubtitle;
        document.getElementById('heroBgImage').value = homepageSettings.heroBgImage;
        document.getElementById('stat1Text').value = homepageSettings.stat1Text;
        document.getElementById('stat2Text').value = homepageSettings.stat2Text;
        document.getElementById('stat3Text').value = homepageSettings.stat3Text;
        document.getElementById('serviceRankDesc').value = homepageSettings.serviceDescriptions.rank;
        document.getElementById('serviceTeachDesc').value = homepageSettings.serviceDescriptions.teach;
        document.getElementById('serviceTeamDesc').value = homepageSettings.serviceDescriptions.team;
        document.getElementById('serviceTacticsDesc').value = homepageSettings.serviceDescriptions.tactics;

        // 应用设置到首页
        this.applyHomepageSettings();
    }

    applyHomepageSettings() {
        const homepageSettings = JSON.parse(localStorage.getItem('homepageSettings')) || {
            heroTitle: '永劫无间专业陪玩服务',
            heroSubtitle: '顶级技术大神带你飞，专业团队，安全可靠',
            heroBgImage: '',
            stat1Text: '1000+满意客户',
            stat2Text: '50+专业陪玩',
            stat3Text: '99%好评率',
            serviceDescriptions: {
                rank: '专业大神带你上分，快速提升段位',
                teach: '一对一指导，掌握核心技巧',
                team: '与大神组队，体验高端局',
                tactics: '战术分析，制定专属策略'
            }
        };

        // 更新首页文字
        const heroTitleEl = document.querySelector('.hero-content h2');
        const heroSubtitleEl = document.querySelector('.hero-content p');
        const statTexts = document.querySelectorAll('.stat-label');
        const serviceDescs = document.querySelectorAll('.service-card p');

        if (heroTitleEl) heroTitleEl.textContent = homepageSettings.heroTitle;
        if (heroSubtitleEl) heroSubtitleEl.textContent = homepageSettings.heroSubtitle;
        
        if (statTexts.length >= 3) {
            statTexts[0].textContent = homepageSettings.stat1Text;
            statTexts[1].textContent = homepageSettings.stat2Text;
            statTexts[2].textContent = homepageSettings.stat3Text;
        }

        // 更新服务介绍
        const serviceCards = document.querySelectorAll('.service-card');
        serviceCards.forEach((card, index) => {
            const desc = card.querySelector('p');
            if (desc) {
                const serviceType = card.querySelector('.price').getAttribute('data-price');
                if (homepageSettings.serviceDescriptions[serviceType]) {
                    desc.textContent = homepageSettings.serviceDescriptions[serviceType];
                }
            }
        });

        // 更新背景图
        const heroSection = document.querySelector('.hero');
        if (heroSection) {
            if (homepageSettings.heroBgImage) {
                heroSection.style.background = `linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5)), url(${homepageSettings.heroBgImage})`;
                heroSection.style.backgroundSize = 'cover';
                heroSection.style.backgroundPosition = 'center';
            } else {
                heroSection.style.background = 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)';
            }
        }
    }

    updateBackground() {
        const bgImage = document.getElementById('heroBgImage').value;
        const homepageSettings = JSON.parse(localStorage.getItem('homepageSettings')) || {};
        homepageSettings.heroBgImage = bgImage;
        localStorage.setItem('homepageSettings', JSON.stringify(homepageSettings));
        this.applyHomepageSettings();
        alert('背景图已更新！');
    }

    updateHeroText() {
        const homepageSettings = JSON.parse(localStorage.getItem('homepageSettings')) || {};
        homepageSettings.heroTitle = document.getElementById('heroTitle').value || '永劫无间专业陪玩服务';
        homepageSettings.heroSubtitle = document.getElementById('heroSubtitle').value || '顶级技术大神带你飞，专业团队，安全可靠';
        homepageSettings.stat1Text = document.getElementById('stat1Text').value || '1000+满意客户';
        homepageSettings.stat2Text = document.getElementById('stat2Text').value || '50+专业陪玩';
        homepageSettings.stat3Text = document.getElementById('stat3Text').value || '99%好评率';
        localStorage.setItem('homepageSettings', JSON.stringify(homepageSettings));
        this.applyHomepageSettings();
        alert('首页文字已更新！');
    }

    updateServiceDescriptions() {
        const homepageSettings = JSON.parse(localStorage.getItem('homepageSettings')) || {};
        homepageSettings.serviceDescriptions = {
            rank: document.getElementById('serviceRankDesc').value || '专业大神带你上分，快速提升段位',
            teach: document.getElementById('serviceTeachDesc').value || '一对一指导，掌握核心技巧',
            team: document.getElementById('serviceTeamDesc').value || '与大神组队，体验高端局',
            tactics: document.getElementById('serviceTacticsDesc').value || '战术分析，制定专属策略'
        };
        localStorage.setItem('homepageSettings', JSON.stringify(homepageSettings));
        this.applyHomepageSettings();
        alert('服务介绍已更新！');
    }

    handleBgUpload(event) {
        const file = event.target.files[0];
        if (file) {
            if (file.size > 2 * 1024 * 1024) { // 2MB限制
                alert('图片大小不能超过2MB！');
                return;
            }
            
            if (!file.type.startsWith('image/')) {
                alert('请上传图片文件！');
                return;
            }

            const reader = new FileReader();
            reader.onload = (e) => {
                document.getElementById('heroBgImage').value = e.target.result;
            };
            reader.readAsDataURL(file);
        }
    }

    saveBookings() {
        localStorage.setItem('bookings', JSON.stringify(this.bookings));
    }

    savePrices() {
        localStorage.setItem('prices', JSON.stringify(this.prices));
    }

    saveActivities() {
        localStorage.setItem('activities', JSON.stringify(this.activities));
    }

    saveSettings() {
        localStorage.setItem('settings', JSON.stringify(this.settings));
    }

    // UI Helper Functions
    scrollToSection(sectionId) {
        const section = document.getElementById(sectionId);
        if (section) {
            section.scrollIntoView({ behavior: 'smooth' });
            
            // Update active nav link
            document.querySelectorAll('.nav-link').forEach(link => {
                link.classList.remove('active');
            });
            document.querySelector(`[href="#${sectionId}"]`).classList.add('active');
        }
    }

    openAdminModal() {
        console.log('打开管理员登录窗口');
        const modal = document.getElementById('adminModal');
        if (modal) {
            modal.style.display = 'block';
        } else {
            console.error('找不到管理员模态框');
        }
    }

    closeAdminModal() {
        document.getElementById('adminModal').style.display = 'none';
        // 不重置表单，保持预填值
    }
}

// Tab management
function showTab(tabName) {
    // Hide all tab contents
    document.querySelectorAll('.tab-content').forEach(content => {
        content.style.display = 'none';
    });
    
    // Remove active class from all tab buttons
    document.querySelectorAll('.tab-btn').forEach(btn => {
        btn.classList.remove('active');
    });
    
    // Show selected tab content
    document.getElementById(`${tabName}Tab`).style.display = 'block';
    
    // Add active class to selected tab button
    event.target.classList.add('active');
}

// Global functions for HTML onclick events
function scrollToBooking() {
    reservationSystem.scrollToSection('book');
}

function closeAdminModal() {
    reservationSystem.closeAdminModal();
}

function logoutAdmin() {
    reservationSystem.logoutAdmin();
}

function updatePrices() {
    reservationSystem.updatePrices();
}

function addActivity() {
    reservationSystem.addActivity();
}

function updateSettings() {
    reservationSystem.updateSettings();
}

function updateBackground() {
    reservationSystem.updateBackground();
}

function updateHeroText() {
    reservationSystem.updateHeroText();
}

function updateServiceDescriptions() {
    reservationSystem.updateServiceDescriptions();
}

function handleBgUpload(event) {
    reservationSystem.handleBgUpload(event);
}

// Initialize the system
const reservationSystem = new ReservationSystem();

// Close modals when clicking outside
window.onclick = function(event) {
    const modal = document.getElementById('adminModal');
    if (event.target === modal) {
        reservationSystem.closeAdminModal();
    }
}

// Date/time validation
document.addEventListener('DOMContentLoaded', function() {
    const bookingTimeInput = document.getElementById('bookingTime');
    if (bookingTimeInput) {
        const now = new Date();
        now.setMinutes(now.getMinutes() + 30); // Minimum 30 minutes from now
        bookingTimeInput.min = now.toISOString().slice(0, 16);
    }
});